package com.aaa.controller.sas;


import com.aaa.entity.LayData;
import com.aaa.entity.MyPage;
import com.aaa.entity.sas.TSasSub;
import com.aaa.service.sas.TSasSubService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * (TSasSub)表控制层
 *
 * @author makejava
 * @since 2022-10-29 00:49:01
 */
@Controller
@RequestMapping("tSasSub")
public class TSasSubController {
    /**
     * 服务对象
     */
    @Autowired
    private TSasSubService tSasSubService;

    /*
        查询SAS试题
     */
    @GetMapping("queryAll")
    @ResponseBody
    public LayData queryAll(MyPage page, TSasSub tSasSub){
        PageInfo pageInfo = tSasSubService.queryAll(page,tSasSub);
        return new LayData(pageInfo);
    }

    /*
        批量导入Excel中的数据
     */
    @RequestMapping("importExcel")
    @ResponseBody
    public LayData importExcel(MultipartFile file){
        Boolean i = tSasSubService.importExcel(file);
        return new LayData(i);
    }

    /*
        添加/修改题目
     */
    @PostMapping("addOrUpdataSASTitle")
    @ResponseBody
    public LayData addOrUpdataSASTitle(TSasSub tSasSub){
        Boolean i = tSasSubService.addOrUpdataSASTitle(tSasSub);
        return new LayData(i);
    }

    /*
       删除题目
    */
    @DeleteMapping("delSasTitle/{sasnumber}")
    @ResponseBody
    public LayData delSasTitle(@PathVariable Integer sasnumber){
        Boolean i = tSasSubService.delSasTitle(sasnumber);
        return new LayData(i);
    }

    /*
        批量删除题目（做过的不删）
     */
    @PostMapping("delSasnumbers/{sasnumbers}")
    @ResponseBody
    public LayData delSasnumbers(@PathVariable Integer[] sasnumbers){
        List<Integer> nodellist = tSasSubService.delSasnumbers(sasnumbers);
        return new LayData(nodellist);
    }

    /*
        添加前检查编号是否存在
     */
    @PostMapping("{sasnumber}")
    @ResponseBody
    public LayData checkSasNumber(@PathVariable Integer sasnumber){
        Boolean i = tSasSubService.checkSasNumber(sasnumber);
        return new LayData(i);
    }

     /*
        将数据传到主页面上
     */
    @GetMapping("index")
    public String getIndexAllSub(MyPage page, HttpServletRequest request){
        page.setLimit(20);
        page.setPage(1);

        PageInfo pageInfo = tSasSubService.getIndexAllSub(page);
        request.setAttribute("allsub",pageInfo);

        return "/sas/index";
    }
}
